<template>
  <div class="comment">
    <message-tree v-bind="$attrs" @listRecord="listRecord" @addRecord="addRecord" @deleteRecord="deleteRecord" @tagsRecord="tagsRecord" />
  </div>
</template>

<script>
import moment from 'moment';
export default {
  components: {},
  props: {
    // businessId: {
    //   validator(value) {
    //     return Number.isInteger(value);
    //   },
    //   default: null,
    // },
    // businessKey: {
    //   type: String,
    // },
    // businessExtend: {
    //   validator(value) {
    //     return Number.isInteger(value);
    //   },
    //   default: null,
    // },
  },
  data() {
    return {};
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    listRecord(params, cb) {
      return new Promise((resolve) => {
        setTimeout(
          () =>
            resolve({
              total: 3,
              rows: [
                {
                  remark: null,
                  id: 4,
                  userId: 1,
                  toUserId: null,
                  commentMsg: '23',
                  tagsCount: 1,
                  replyCount: 0,
                  commentDate: '2021-11-11 14:17:15',
                  userInfo: { userName: '管理员', avatar: 'https://jinqi-oa.oss-cn-chengdu.aliyuncs.com/profile/avatar/20210923/a34f83d7-0544-4314-835e-449c4474ad60.jpeg' },
                  toUserInfo: null,
                  ownerTags: '1',
                  ancestorId: 0,
                },
                {
                  remark: null,
                  id: 2,
                  userId: 1,
                  toUserId: null,
                  commentMsg: '21345',
                  tagsCount: 0,
                  replyCount: 1,
                  commentDate: '2021-11-11 14:02:48',
                  userInfo: { userName: '管理员', avatar: 'https://jinqi-oa.oss-cn-chengdu.aliyuncs.com/profile/avatar/20210923/a34f83d7-0544-4314-835e-449c4474ad60.jpeg' },
                  toUserInfo: null,
                  ownerTags: '0',
                  ancestorId: 0,
                },
                {
                  remark: null,
                  id: 3,
                  userId: 1,
                  toUserId: null,
                  commentMsg: '1',
                  tagsCount: 0,
                  replyCount: 0,
                  commentDate: '2021-11-11 14:17:12',
                  userInfo: { userName: '管理员', avatar: 'https://jinqi-oa.oss-cn-chengdu.aliyuncs.com/profile/avatar/20210923/a34f83d7-0544-4314-835e-449c4474ad60.jpeg' },
                  toUserInfo: null,
                  ownerTags: '0',
                  ancestorId: 0,
                },
              ],
            }),
          300
        );
      }).then(cb);
    },
    addRecord(params, cb) {
      return new Promise((resolve) => {
        const res = {
          code: 200,
          data: {
            remark: null,
            id: moment().format('x'),
            userId: 1,
            toUserId: null,
            commentMsg: params.commentMsg,
            tagsCount: null,
            replyCount: null,
            commentDate: moment().format('YYYY-MM-DD HH:mm'),
            userInfo: { userName: '管理员', avatar: 'https://jinqi-oa.oss-cn-chengdu.aliyuncs.com/profile/avatar/20210923/a34f83d7-0544-4314-835e-449c4474ad60.jpeg' },
            toUserInfo: null,
            ownerTags: null,
            ancestorId: 0,
          },
        };
        setTimeout(() => {
          if (res.code === 200) {
            this.$message({ showClose: true, message: '评论成功', type: 'success' });
            resolve(res.data);
          }
        });
      }).then(cb);
    },
    deleteRecord(params, cb) {
      return new Promise((resolve) => {
        const res = { code: 200 };
        setTimeout(() => {
          if (res.code === 200) {
            this.$message({ showClose: true, message: '删除成功', type: 'success' });
            resolve();
          }
        });
      }).then(cb);
    },
    tagsRecord(params, cb) {
      return new Promise((resolve) => {
        const res = { code: 200, data: 2 };
        setTimeout(() => {
          if (res.code === 200) {
            resolve(res.data);
          }
        });
      }).then(cb);
    },
  },
};
</script>

<style scoped lang="scss"></style>
